package com.zhiying.service.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.zhiying.domain.CMS_User;
import com.zhiying.domain.User;
import com.zhiying.jpa.ReLogin;
import com.zhiying.service.LoginService;


@Transactional
@Service
@Component
public class LoginServiceImpl implements LoginService {


	@PersistenceContext
	EntityManager entityManager;

	@Autowired
	ReLogin reLogin;

	//	@CacheEvict(value="common")
	@Cacheable(cacheNames = "product", key = "123")
	//	@CachePut(cacheNames="product",key="123")
	public List<User> showUser(Pageable pageable,String name,int pwd) {
		// TODO Auto-generated method stub
		//		update();
		//		List<User> list=entityManager.createQuery("")
		//				.setFirstResult(1)
		//				.setMaxResults(10)
		//				.getResultList();
		return reLogin.getUser(pageable,name,pwd);
	}

	public void insertUser(User user) {
		// TODO Auto-generated method stub
		/* reLogin.save(user); */
	}

	@CacheEvict(cacheNames="product",key="123")
	public void delUser() {
		// 删除user
		System.out.println("product删除");
	}

	//	@Scheduled(cron = "0 20 23 ? * * ") //每天凌晨4:30执行
	//	@Scheduled(fixedRate=6000) //每天凌晨4:30执行
	//	@CachePut(cacheNames="product",key="123")
	//	public void update() {
	//		System.out.println("product更新成功");
	//	}
	//	public List<User> showUsers() {
	//		// TODO Auto-generated method stub
	//		List<User> list=entityManager.createQuery("from User")
	//		return null;
	//	}
	//	

	@Override
	public CMS_User getUserInfoByByPasswordandUser(@Param("loginName") String loginname,@Param("loginPassword") String password) {
		// TODO Auto-generated method stub

		return reLogin.getUserInfoByByPasswordandUser(loginname,password);

	}

	@Override
	public void update() {
		// TODO Auto-generated method stub

	}

	@Override
	public CMS_User getUserInfoByUserName(String loginname) {
		/* 根据用户名查询用户信息 */
		return reLogin.getUserInfoByUserName(loginname);
	}
	//	@Servicepublic class AreaServiceImpl implements AreaService {   
	//		@Autowired
	//	    private AreaDao areaDao;    
	//		@Override
	//	    @Transactional
	//	    @Cacheable(value = "common")    //@CacheEvict(value="common")
	//	    public List<Area> getAreaList() {        return areaDao.queryArea();
	//	    }
	//
	//	}



}
